<?php if(!defined('BASE_PATH')) exit('No Access!');

class Super_Config {

	public static function &load($configfile){

        //先在项目目录下查找是否存在该配置文件
        $user_config_path = BASE_PATH;
        if(strpos('/',$configfile) === FALSE){
            if($GLOBALS['SUPER']['enable_module'] === TRUE) {
                $user_config_path .= '/'.$GLOBALS['SUPER']['current_module'];
            }
            $user_config_path .= '/config';
        }
        if(file_exists($user_config_path.'/'.$configfile.'.php')){
            include $user_config_path.'/'.$configfile.'.php';
            $new_config = $$configfile;
            if(is_array($new_config) && !empty($new_config)){
                foreach($new_config as $key=>$val){
                    $GLOBALS['SUPER'][$key] = $val;
                }
            } elseif($new_config) {
                $GLOBALS['SUPER'][$configfile] = $new_config;
            }
            return;
        }

        //然后查找框架核心目录
        $sys_config_path = SUPER_PATH;
        if(file_exists($sys_config_path.'/'.$configfile.'.php')){
            include $sys_config_path.'/'.$configfile.'.php';
            $new_config = $$configfile;
            if(is_array($new_config) && !empty($new_config)){
                foreach($new_config as $key=>$val){
                    $GLOBALS['SUPER'][$key] = $val;
                }
            } elseif($new_config) {
                $GLOBALS['SUPER'][$configfile] = $new_config;
            }
            return;
        }

        //查找框架配置文件目录
        if(file_exists($sys_config_path.'/Config/'.$configfile.'.php')){
            include $sys_config_path.'/'.$configfile.'.php';
            $new_config = $$configfile;
            if(is_array($new_config) && !empty($new_config)){
                foreach($new_config as $key=>$val){
                    $GLOBALS['SUPER'][$key] = $val;
                }
            } elseif($new_config) {
                $GLOBALS['SUPER'][$configfile] = $new_config;
            }
            return;
        }

		return;
	}

	public static function get($key){
		if(isset($this->config[$key])) return $this->config[$key];
		else return FALSE;
	}

	public static function aaa(){
		echo '111111';exit;
	}

	public static function set($key,$val){
		$this->config[$key] = $val;
		$GLOBALS['SUPER'][$key] = $val;
		return $GLOBALS['SUPER'][$key];
	}

}